package com.slipper.system.codeless.controller;

import com.slipper.system.codeless.bo.PageParamBO;
import com.slipper.system.codeless.service.PageParamService;
import com.slipper.system.menu.bo.MenuBO;
import com.slipper.system.menu.service.MenuService;
import com.slipper.util.ResultUtil;
import com.slipper.util.Tool;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 页面参数信息表
 */
@RestController
@RequestMapping("/system/pageParam")
public class PageParamController {
    @Resource
    private PageParamService pageParamService;
    @Resource
    private MenuService menuService;

    @PostMapping(value = "/queryList")
    public String queryList(@RequestBody PageParamBO bo) {
        return ResultUtil.successResult(pageParamService.queryList(bo));
    }

    @PostMapping(value = "/queryListByMenuId")
    public String queryListByMenuId(@RequestBody MenuBO bo) {
        MenuBO menuBO = menuService.queryBy(bo.getId());
        if (menuBO == null || Tool.isBlank(menuBO.getPageId())) {
            return ResultUtil.failureResult("参数不正确！");
        }

        PageParamBO qo = new PageParamBO();
        qo.setPageId(menuBO.getPageId());
        return ResultUtil.successResult(pageParamService.queryList(qo));
    }
}
